package com.iov.failure.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.iov.failure.vo.FailureVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.iov.failure.domain.TbFailure;
import com.iov.failure.service.ITbFailureService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 故障列Controller
 * 
 * @author ruoyi
 * @date 2023-11-17
 */
@RestController
@RequestMapping("/failure")
public class TbFailureController extends BaseController
{
    @Autowired
    private ITbFailureService tbFailureService;

    /**
     * 查询故障列列表
     */
    @RequiresPermissions("failure:failure:list")
    @GetMapping("/list")
    public TableDataInfo list(TbFailure tbFailure)
    {
        startPage();
        List<TbFailure> list = tbFailureService.selectTbFailureList(tbFailure);
        return getDataTable(list);
    }
    /**
    * @description: //TODO
     *   redis 分页 加上 查询
    * @param: [tbFailure]
    * @return: com.ruoyi.common.core.web.page.TableDataInfo
    * @author Administrator
    * @date: 2023/11/22 22:23
    */
    @RequiresPermissions("failure:failure:listfailure")
    @GetMapping("/listfailure")
    public TableDataInfo listFailure(FailureVo failureVo){

        TableDataInfo tableDataInfo = tbFailureService.queryListFailure(failureVo);
        return tableDataInfo;

    }

    /**
     * 导出故障列列表
     */
    @RequiresPermissions("failure:failure:export")
    @Log(title = "故障列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbFailure tbFailure)
    {
        List<TbFailure> list = tbFailureService.selectTbFailureList(tbFailure);
        ExcelUtil<TbFailure> util = new ExcelUtil<TbFailure>(TbFailure.class);
        util.exportExcel(response, list, "故障列数据");
    }

    /**
     * 获取故障列详细信息
     */
    @RequiresPermissions("failure:failure:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbFailureService.selectTbFailureById(id));
    }

    /**
     * 新增故障列
     */
    @RequiresPermissions("failure:failure:add")
    @Log(title = "故障列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbFailure tbFailure)
    {
        return toAjax(tbFailureService.insertTbFailure(tbFailure));
    }

    /**
     * 修改故障列
     */
    @RequiresPermissions("failure:failure:edit")
    @Log(title = "故障列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbFailure tbFailure)
    {
        return toAjax(tbFailureService.updateTbFailure(tbFailure));
    }

    /**
     * 删除故障列
     */
    @RequiresPermissions("failure:failure:remove")
    @Log(title = "故障列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbFailureService.deleteTbFailureByIds(ids));
    }
}
